package com.example.greetingcard

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.example.greetingcard.DashboardFragment
import com.example.greetingcard.HomeFragment
import com.example.greetingcard.NotificationsFragment
import com.example.greetingcard.R
import com.google.android.material.bottomnavigation.BottomNavigationView

class MainActivity : AppCompatActivity() {

    private lateinit var bottomNavigationView: BottomNavigationView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        bottomNavigationView = findViewById(R.id.bottom_navigation)
        bottomNavigationView.setOnItemSelectedListener { item ->
            when (item.itemId) {
                R.id.menu_home -> {
                    replaceFragment(HomeFragment())
                    true
                }
                R.id.menu_dashboard -> {
                    replaceFragment(DashboardFragment())
                    true
                }
                R.id.menu_notifications -> {
                    replaceFragment(NotificationsFragment())
                    true
                }
                else -> false
            }
        }

        // 默认显示首页
        replaceFragment(HomeFragment())
    }

    private fun replaceFragment(fragment: Fragment) {
        supportFragmentManager.beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commit()
    }
}